package org.jeecg.modules.goods.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.modules.goods.entity.Goods;
import org.jeecg.modules.goods.mapper.GoodsMapper;
import org.jeecg.modules.goods.service.IGoodsService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @Description: 商品管理
 * @Author: jeecg-boot
 * @Date:   2024-07-10
 * @Version: V1.0
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {

    @Override
    public BigDecimal goodsPrice(Map goodsMap) {
        List<Goods> goods = this.baseMapper.selectList(new LambdaQueryWrapper<Goods>().in(Goods::getId,goodsMap.keySet()));
        BigDecimal amt = new BigDecimal(0);
        if(CollectionUtil.isNotEmpty(goods)){
            for(Goods good:goods){
                amt = amt.add(good.getDisAmt().multiply(new BigDecimal(goodsMap.get(good.getId()).toString())));
            }
        }
        return amt;
    }
}
